package com.suirich.service.impl;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.suirich.bean.Product;
import com.suirich.common.Page;
import com.suirich.service.BaseService;
import com.suirich.service.ProductService;

@Service
@Transactional
public class ProductServiceImpl extends BaseService implements ProductService {

	public void create(Product product) {
		this.productDao.create(product);
	}

	public Product read(Long id) {
	    Product product = this.productDao.read(id);
	    
        try {
            String productReadmeInfo = "";
            byte[] b = (byte[])product.getProductReadme();
            
            if(b != null){
                productReadmeInfo = new String(b,"UTF-8");
            }else{
                productReadmeInfo = "No content！";
            }
            product.setProductReadmeInfo(productReadmeInfo);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        
		return product;
	}

	public void delete(Product product) {
		this.productDao.delete(product);
	}

	public List<Product> getProductList(Page page) {
		return this.productDao.getProductList(page);
	}

	public Long getProductListCount() {
		return this.productDao.getProductListCount();
	}

    public void update(Product product) {
        this.productDao.update(product);
    }

    public List<Product> getProductListByCondition(String newRelease,List<Long> categories,Page page) {
        return this.productDao.getProductListByCondition(newRelease,categories,page);
    }

    public Long getProductListByConditionCount(String newRelease,
            List<Long> categories) {
        return this.productDao.getProductListByConditionCount(newRelease, categories);
    }


}
